<template>
	<view class="main">
		<view class="name_wrap">
			<input v-if="type == 0" :maxlength="type == 0 ? 10 : 100" style="width: 100%;" type="text" v-model="content"
				:placeholder="placeholder" />
			<textarea class="textarea" v-else v-model="content" maxlength="100" cols="30" rows="10"></textarea>
		</view>
		<view class="tips">
			{{ type == 0 ? '长度限制在10个字符内' : '长度限制在100个字符内' }}
		</view>
	</view>
</template>

<script>
import { getUserInfo, editUserInfo } from '@/api/my.js'
export default {
	data() {
		return {
			userInfo: {},
			content: '',
			placeholder: '',
		}
	},
	methods: {
		//修改个人昵称
		save() {
			const params = {
				rLoading: true,
				[this.type == 0 ? 'nickname' : 'bio']: this.content
			};
			editUserInfo(params).then(res => {
				console.log("editUserInfo 请求结果", res);
				if (res.code == 1) {
					this.$used.appBack('修改成功')
					this.getUserInfo()
				} else {
					this.$used.msg(res.msg)
				}
			})
		},
		//获取个人信息
		getUserInfo() {
			getUserInfo({}).then((res) => {
				this.userInfo = res.data
			})
		},
	},
	onNavigationBarButtonTap() {
		this.save()
	},
	onLoad(e) {
		this.type = e.type
		this.content = e.name
		this.placeholder = this.type == 0 ? '输入您的昵称' : '输入您的个人简介'
		if (e.type == 1) {
			uni.setNavigationBarTitle({
				title: '设置个人介绍'
			})
		}
	},
}
</script>

<style lang="scss" scoped>
.main {
	position: relative;
	min-height: 94vh;
	background-color: #F9F7FC;
	padding-top: 20rpx;
	box-sizing: border-box;

	.name_wrap {
		padding: 0 30rpx;
		display: flex;
		align-items: center;
		min-height: 120rpx;
		background: #FFFFFF;

		.textarea {
			padding: 15rpx;
		}
	}

	.tips {
		text-align: right;
		padding: 30rpx;
		font-size: 24rpx;
		color: #9E9E9E;
	}
}
</style>
